package org.extremecomponents.table.view.freemarker.extend;

import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.view.html.BuilderUtils;
import org.extremecomponents.table.view.html.FormBuilder;
import org.extremecomponents.table.view.html.ToolbarBuilder;
import org.extremecomponents.util.HtmlBuilder;

/**
 * @author Eccn-sshwsfc
 *
 */
public class TableExtend {

	private TableModel model;

	public TableExtend(TableModel model) {
		this.model = model;
	}
	
	public boolean isShowExports(){
		return BuilderUtils.showExports(model);
	}
	
    public String getPrefixId() {
        return model.getTableHandler().getTable().getTableId() + "_";
    }
    
    public String getDefinedParameters() {
    	HtmlBuilder html = new HtmlBuilder();
    	new FormBuilder(html, model).userDefinedParameters();
    	return html.toString();
    }
	
	public String getAjaxSender() {
		return model.getTableHandler().getTable().getAttributeAsString("ajaxSender");
	}
	
	public String getRowsDisplayedDroplist() {
		ToolbarBuilder builder = new ToolbarBuilder(model);
		builder.rowsDisplayedDroplist();
		return builder.getHtmlBuilder().toString();
	}
	
	public boolean isAjaxEnable() {
		return model.getTableHandler().getTable().getAttribute("ajaxSender") != null;
	}
    
    public String getAllHiddens() {
    	HtmlBuilder html = new HtmlBuilder();
    	FormBuilder formBuilder = new FormBuilder(html, model);

    	formBuilder.instanceParameter();
    	formBuilder.exportParameters();
    	formBuilder.rowsDisplayedParameter();
    	formBuilder.filterParameter();
    	formBuilder.pageParameters();
    	formBuilder.sortParameters();
    	formBuilder.userDefinedParameters();
    	
    	return html.toString();
    }
}
